package c.g.a.a;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.io.File;

/* compiled from: DeviceDatabase */
public class a extends SQLiteOpenHelper {
    public final File a;
    public final Context b;

    public a(Context context) {
        String str = "android-devices.db";
        super(context, str, null, 1);
        this.b = context.getApplicationContext();
        File databasePath = context.getDatabasePath(str);
        this.a = databasePath;
        if (!databasePath.exists()) {
            n();
        }
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:8:0x002e */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Can't wrap try/catch for region: R(9:0|1|(2:2|(1:4)(1:14))|5|6|7|8|9|15) */
    /* JADX WARNING: Missing block: B:16:?, code skipped:
            return;
     */
    public final void n() throws android.database.SQLException {
        /*
        r5 = this;
        r5.getReadableDatabase();	 Catch:{ IOException -> 0x0032 }
        r5.close();	 Catch:{ IOException -> 0x0032 }
        r0 = r5.b;	 Catch:{ IOException -> 0x0032 }
        r0 = r0.getAssets();	 Catch:{ IOException -> 0x0032 }
        r1 = "android-devices.db";
        r0 = r0.open(r1);	 Catch:{ IOException -> 0x0032 }
        r1 = new java.io.FileOutputStream;	 Catch:{ IOException -> 0x0032 }
        r2 = r5.a;	 Catch:{ IOException -> 0x0032 }
        r1.<init>(r2);	 Catch:{ IOException -> 0x0032 }
        r2 = 2048; // 0x800 float:2.87E-42 double:1.0118E-320;
        r2 = new byte[r2];	 Catch:{ IOException -> 0x0032 }
    L_0x001d:
        r3 = r0.read(r2);	 Catch:{ IOException -> 0x0032 }
        if (r3 <= 0) goto L_0x0028;
    L_0x0023:
        r4 = 0;
        r1.write(r2, r4, r3);	 Catch:{ IOException -> 0x0032 }
        goto L_0x001d;
    L_0x0028:
        r1.flush();	 Catch:{ IOException -> 0x0032 }
        r1.close();	 Catch:{ IOException -> 0x002e }
    L_0x002e:
        r0.close();	 Catch:{ IOException -> 0x0031 }
    L_0x0031:
        return;
    L_0x0032:
        r0 = move-exception;
        r1 = new android.database.SQLException;
        r2 = "Error creating android-devices.db database";
        r1.<init>(r2, r0);
        throw r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.g.a.a.a.n():void");
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:16:0x0077 */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Can't wrap try/catch for region: R(9:0|(2:5|(1:7)(3:8|(1:10)|18))(1:4)|11|(1:13)|14|15|16|17|18) */
    public c.g.a.a.d o(java.lang.String r14, java.lang.String r15) {
        /*
        r13 = this;
        r8 = r13.getReadableDatabase();
        r9 = "name";
        r10 = "codename";
        r11 = "model";
        r2 = new java.lang.String[]{r9, r10, r11};
        r0 = android.text.TextUtils.isEmpty(r14);
        r12 = 0;
        r1 = 0;
        r3 = 1;
        if (r0 != 0) goto L_0x0029;
    L_0x0017:
        r0 = android.text.TextUtils.isEmpty(r15);
        if (r0 != 0) goto L_0x0029;
    L_0x001d:
        r0 = 2;
        r0 = new java.lang.String[r0];
        r0[r1] = r14;
        r0[r3] = r15;
        r14 = "codename LIKE ? OR model LIKE ?";
        r3 = r14;
        r4 = r0;
        goto L_0x0046;
    L_0x0029:
        r0 = android.text.TextUtils.isEmpty(r14);
        if (r0 != 0) goto L_0x0038;
    L_0x002f:
        r15 = new java.lang.String[r3];
        r15[r1] = r14;
        r14 = "codename LIKE ?";
        r3 = r14;
        r4 = r15;
        goto L_0x0046;
    L_0x0038:
        r14 = android.text.TextUtils.isEmpty(r15);
        if (r14 == 0) goto L_0x007a;
    L_0x003e:
        r14 = new java.lang.String[r3];
        r14[r1] = r15;
        r15 = "model LIKE ?";
        r4 = r14;
        r3 = r15;
    L_0x0046:
        r5 = 0;
        r6 = 0;
        r7 = 0;
        r1 = "devices";
        r0 = r8;
        r14 = r0.query(r1, r2, r3, r4, r5, r6, r7);
        r15 = r14.moveToFirst();
        if (r15 == 0) goto L_0x0074;
    L_0x0056:
        r15 = r14.getColumnIndexOrThrow(r9);
        r15 = r14.getString(r15);
        r0 = r14.getColumnIndexOrThrow(r10);
        r0 = r14.getString(r0);
        r1 = r14.getColumnIndexOrThrow(r11);
        r1 = r14.getString(r1);
        r2 = new c.g.a.a.d;
        r2.m1927init(r12, r15, r0, r1);
        r12 = r2;
    L_0x0074:
        r14.close();	 Catch:{ IOException -> 0x0077 }
    L_0x0077:
        r8.close();	 Catch:{ IOException -> 0x007a }
    L_0x007a:
        return r12;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.g.a.a.a.o(java.lang.String, java.lang.String):c.g.a.a.d");
    }

    public void onCreate(SQLiteDatabase sQLiteDatabase) {
    }

    public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
        if (i2 <= i) {
            return;
        }
        if (this.b.deleteDatabase("android-devices.db") || this.a.delete() || !this.a.exists()) {
            n();
        }
    }
}
